﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ZLDC.Common.Estate;
using System.Data;
using System.Web;
using System.Web.UI.WebControls;
namespace ZLDC.Topo.BLL.Estate
{
    public class lp_Addition_regiht
    {
        public static string GetDEPT(string deptid,string type,string station)
        {
            StringBuilder sb = new StringBuilder();
            string sql;
            if (type == "0")
            {
                sql = "select id as deptid,name,parent_id,type from t_zlhq_t_s_alldept where DltFlg=0 and parent_id = (select parent_id from t_zlhq_t_s_alldept where Id=" + deptid + "  )   ";
            }
            else
            {
                sql = "select id as deptid,name,parent_id,type from t_zlhq_t_s_alldept where DltFlg=0 and parent_id in (select parent_id from t_zlhq_t_s_alldept where  parent_id=" + deptid + "  )";    
            }
                DataSet ds = ZLDC.Topo.BLL.Estate.lp_Basis.Getds(sql);
            sb.Append("<table border='0' cellpadding=\"0\" cellspacing=\"0\">");
            sb.Append("<tr>");
            int j = 0;
            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                if (j > 0 && j % 4 == 0)
                {
                    sb.Append("</tr>");
                    sb.Append("<tr>");
                }
                j++;
                sb.Append("<td valign='top'>");
                sb.Append("<table style='text-align:center;margin-top:5px;margin-left:5px;' border='0' cellpadding=\"0\" cellspacing=\"1\"><tr><td  bgcolor='d3eaef' class='STYLE10' colspan=\"3\">");
                sb.Append("<a onclick=\"deptlist('" + ds.Tables[0].Rows[i]["name"].ToString() + "'," + ds.Tables[0].Rows[i]["deptid"].ToString() + ",'" + station + "','" + ds.Tables[0].Rows[i]["type"].ToString() + "')\">" + ds.Tables[0].Rows[i]["name"].ToString() + "</a>");
                sb.Append("</td></tr>");

                sb.Append("<tr>");
                sb.Append("<td style='width:200px;text-align:center;' colspan=\"3\">");
                sb.Append(GetPeoPleList(ds.Tables[0].Rows[i]["deptid"].ToString()));
                sb.Append("</td>");
                sb.Append("</tr>");
                sb.Append("<tr>");
                sb.Append("<td colspan=\"2\">");
                                                                                                                                
                                sb.Append("<td>");
                sb.Append("</tr>");
                sb.Append("</table>");
                sb.Append("</td>");
            }
            sb.Append("</tr>");
            sb.Append("</table>");
            return sb.ToString();
        }
        protected static string GetPeoPleList(string deptid)
        {
                                    string sql = "select * from lp_worklist where work_deptid in (" + ZLDC.Topo.BLL.Estate.lp_Basis.GetDeptxjlist(deptid) + ") and  DATEDIFF(dd, work_daytime, '" + DateTime.Now.ToString("yyyy-MM-dd") + "') = 1 order by work_Actual_Goal desc";
            DataSet ds = ZLDC.Topo.BLL.Estate.lp_Basis.Getds(sql);
            string yg = "<table style='text-align:center;margin-top:5px;margin-left:66px;' border='0' cellpadding=\"0\" cellspacing=\"1\">";
            yg += "<tr>";
            yg += "<td  bgcolor='d3eaef' class='STYLE10'>";
            yg += "部门";
            yg += "</td>";
            yg += "<td  bgcolor='d3eaef' class='STYLE10'>";
            yg += "分数";
            yg += "</td>";
            yg += "</tr>";
            int allaual = 0;
            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                yg += "<tr>";
                yg += "<td>";
                yg += ds.Tables[0].Rows[i]["work_deptname"].ToString();
                yg += "</td>";
                yg += "<td>";
                yg += ds.Tables[0].Rows[i]["work_Actual_Goal"].ToString();
                allaual += int.Parse(ds.Tables[0].Rows[i]["work_Actual_Goal"].ToString()==""?"0":ds.Tables[0].Rows[i]["work_Actual_Goal"].ToString());
                yg += "</td>";
                yg += "</tr>";
            }
            yg += "<tr>";
            yg += "<td  bgcolor='d3eaef' class='STYLE10'>";
            yg += "总分:";
            yg += "</td>";
            yg += "<td  bgcolor='d3eaef' class='STYLE10'>";
            yg += allaual.ToString();
            yg += "</td>";
            yg += "</tr>";
            yg += "</table>";

            return yg;
        }
    }
}
